import datetime

from django.db import transaction
from django.db.models import F
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from store.models import GoodsStock, GoodsTransferDetail, GoodsTransfer


class MobileGoodsStockSerializer(ModelSerializer):
    """
    商品库存
    """
    goods_code = serializers.CharField(source='goods.code', read_only=True)
    goods_name = serializers.CharField(source='goods.name', read_only=True)
    cate_name = serializers.CharField(source='goods.cate.name', read_only=True)
    unit_name = serializers.CharField(source='goods.unit.name', read_only=True)
    house_name = serializers.CharField(source='house.name', read_only=True)
    checked = serializers.BooleanField(read_only=True, default=False)
    nums = serializers.IntegerField(read_only=True, default=1)
    sell_price = serializers.FloatField(read_only=True, default=None)

    class Meta:
        model = GoodsStock
        fields = [
            "id", "goods", "goods_code", "goods_name", "cate_name", "unit_name", "house", "house_name", "specs",
            "quantity", "batch_num", "brand", "place", "checked", "nums", "sell_price"
        ]

